/**
 * 条件查询 
 * @param {Object} form
 */
function search(form){
	var miniForm = new mini.Form(form||"#queryForm"),
		param = miniForm.getData();
	var grid = mini.get("dataGrid");
	grid.load($.extend({pageIndex:0},param));
}
/**
 * 得到表格选择数据
 */
function getSelectData(){
   return mini.get("dataGrid").getSelecteds();
}
/**
 * 刷新数据 
 */
function refrashGrid(){
	mini.get("dataGrid").deselectAll();
	mini.get("dataGrid").reload();
}
/**
 * 打开添加窗口 
 */
function toAddWin(defaultData){
	mini.get('addWin').show();
	new mini.Form('#addForm').clear();//清空表单
	if (NOT_EMPTY(defaultData))
		new mini.Form('#addForm').setData(defaultData);
}
/**
* 保存添加数据
*/
function saveAddData(validate){
	
	if (validate && $.isFunction(validate)){
		if (!validate())
			return;		
	}

	var url = $('#addForm').attr('action');
	submitFormJson("addForm",url,function(){
		refrashGrid();
		closeAddWin();
	});
}
/**
* 关闭窗口
*/
function closeAddWin(){
	mini.get('addWin').hide();//关闭窗口
}
/**
 * 打开修改窗口 
 */
function toEditWin(callback){
	//设置数据
	var datas = getSelectData();
	if (datas.length != 1){
		mini.alert("请选择一条数据编辑!");
		return;
	}
	mini.get('editWin').show();
	new mini.Form("editForm").setData(datas[0]);
	callback && $.isFunction(callback) && callback(datas[0]);
}
/**
* 保存添加数据
*/
function saveEditData(validate){
	if (validate && $.isFunction(validate)){
		if (!validate())
			return;		
	}
	var url = $('#editForm').attr('action');
	submitFormJson("editForm",url,function(){
		refrashGrid();
		closeEditWin();
	});
}
/**
* 关闭修改窗口
*/
function closeEditWin(){
	mini.get('editWin').hide();//关闭窗口
}

/**
* 删除数据
*/
function deleteData(url,id){
	var datas = getSelectData(),
		_id = id || 'id';
	if (datas.length != 1){
		mini.alert("请选择一条数据!");
		return;
	}
	mini.confirm("确定删除该数据吗","提示",function(r){
		if (r == 'ok'){
			var param = {};
				param[_id] = datas[0][_id];
			submitData(url,param,refrashGrid);
		}
	});
}
/**
 * 状态加载时 
 * @param {Object} e
 */
function statusRender(e){
	var val = e.value;
	if (val == "1")
		return "是";
	else if (val == "0")
		return "否";
	else
		return "";
}